--select max(recordid) as id,
--	max(case infocode when 'a' then strcontent end) as 'a',
--	max(case infocode when 'b' then strcontent end) as 'b',
--	max(case infocode when 'c' then strcontent end) as 'c',
--	max(case infocode when 'd' then strcontent end) as 'd'
--from dbo.InfoContent
--group by recordid
--
--select * from InfoContent

declare @infocode varchar(20)
declare @str varchar(2000)
declare @content varchar(2000)

set @str = ''

declare goods_cur cursor for
	select distinct infocode
	from InfoContent

open goods_cur
fetch next from goods_cur into @infocode
while @@fetch_status = 0
begin
	if(@infocode = 'a1' or @infocode = 'c1')
		set @content = 'bytecontent'
	else
		set @content = 'strcontent'
		
	set @str = @str + 'max(case infocode when ''' + @infocode + ''' then ' + @content + ' end) as ''' + @infocode + ''','
	fetch next from goods_cur into @infocode
end
close goods_cur
deallocate goods_cur
set @str = substring(@str,1,len(@str)-1)
print @str

exec('select * from (select max(recordid) as id,' + @str + ' from dbo.InfoContent group by recordid) as t where b like ''%b''')

